<!-- 品牌新增/详情弹窗 -->
<template>
  <div class="brand-detail-main">
    <el-dialog
      title="新增/编辑品牌"
      :visible.sync="dialogVisible"
      width="45%"
      :before-close="handleClose"
    >
      <el-form :model="brand" ref="form" label-width="80px">
        <el-form-item label="品牌名称">
          <el-input v-model="brand.cname" style="width:220px" size="small"></el-input>
        </el-form-item>
        <el-form-item label="英文名称">
          <el-input v-model="brand.ename" style="width:220px" size="small"></el-input>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="封面图片">
              <el-upload
                class="upload-demo"
                ref="upload"
                action="/api/leju/admin/material/uploadImg"
                :on-success="handleSucc"
              >
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-image style="width: 100px; height: 100px" :src="brand.coverImg">
              <div slot="error" class="image-slot">
                <i class="el-icon-picture-outline"></i>
              </div>
            </el-image>
          </el-col>
        </el-row>
        <el-form-item label="描述信息">
          <el-input v-model="brand.descr" type="textarea" size="small"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="doSave">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import brandApi from '@/api/product/brand'
export default {
  name: "brandDetail",
  data() {
    return {
      dialogVisible: false,
      brand: {
        coverImg: "",
      },
    };
  },
  created() {
      
  },
  methods: {
    handleClose() {
      this.dialogVisible = false;
    },

    opendialog() {
      this.dialogVisible = true;
    },

    opendialogEdit(id){//父组件调用该方法,打开弹窗,并获取数据
      this.opendialog()
      brandApi.brandDetail({id})
      .then(res=>{
          this.brand=res.data
      })

      
    },
    handleSucc(response) {
      //图片上传
      this.brand.coverImg = response.ossUrl;
      this.$refs.upload.clearFiles();
    },
    doSave() {
        brandApi.brandSaveOrUpdate(this.brand)
        .then(res=>{
            if(res.code=='error'){
                this.$message.error('提交失败,请重新提交')
            }else{
                this.$message.success('提交成功')            
            }
        })
        this.handleClose()
        this.$emit('refresh-brand')
    },
  },
};
</script>
<style>
</style>